package RuiGe;

import java.util.Scanner;

public class Demo6 {

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        People[] peo=new People[n];
        for(int i=0;i<n;i++){
            int tmp=sc.nextInt();
            String tmoName=sc.next();
            peo[i]=new People(tmp,tmoName);
        }
        int cur=0;
        for(int j=0;j<m;j++){
            int recInput=sc.nextInt();
            int nums=sc.nextInt();
            //如果是左转
            if(recInput==0){
                //如果是面内
                if(peo[cur].rec==0){
                    //如果从尾巴开始
                    if(cur-nums<0){
                        cur=n+cur-nums;
                    }else{
                        cur-=nums;
                    }
                }else{//如果是面外
                    if(cur+nums>=n){
                        cur=cur+nums-n;
                    }else{
                        cur+=nums;
                    }
                }
            }else if(recInput==1){//如果是往右边数
                 if(peo[cur].rec==0){//如果是面内
                     if(cur+nums>=n){
                         cur=cur+nums-n;
                     }else{
                         cur+=nums;
                     }
                 }else{//如果是面外
                     if(cur-nums<0){
                         cur=n+cur-nums;
                     }else{
                         cur-=nums;
                     }
                 }
            }
        }
        System.out.print(peo[cur].name);
    }

    static class People{
        public int rec;
        public String name;

        public People() {
        }

        public People(int rec, String name) {
            this.rec = rec;
            this.name = name;
        }

        /**
         * 获取
         * @return rec
         */
        public int getRec() {
            return rec;
        }

        /**
         * 设置
         * @param rec
         */
        public void setRec(int rec) {
            this.rec = rec;
        }

        /**
         * 获取
         * @return name
         */
        public String getName() {
            return name;
        }

        /**
         * 设置
         * @param name
         */
        public void setName(String name) {
            this.name = name;
        }

        public String toString() {
            return "People{rec = " + rec + ", name = " + name + "}";
        }
    }
}
